<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ include file="ajax.jsp"%>
<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <meta charset="UTF-8">
    <title>欢迎使用后台管理系统</title>
    <style>
        /* 重置样式 */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        /* 页面主体 */
        body {
            font-family: sans-serif;
            background-color: #f5f5f5;
        }

        /* 表格 */
        table {
            width: calc(100% - 20px);
            margin: 0 auto;
            border-collapse: collapse;
            border: 1px solid #ddd;
        }

        th, td {
            border: 1px solid #ddd;
            padding: 5px;
        }

        th {
            text-align: center;
            background-color: #f2f2f2;
        }

        /* 操作按钮 */
        a {
            cursor: pointer;
            display: inline-block;
            padding: 5px 10px;
            border: 1px solid #ccc;
            border-radius: 5px;
            text-decoration: none;
            color: #ccc;
            font-weight: 500;
            background-color: #f54747;
        }

        a:hover {
            background-color: #f30e0e;
        }
    </style>
</head>
<body>
<script>
    function deleteTopic(url){
        axiosInstance.post(
            url,
            {
                headers: headersJson
            }
        ).then((res)=>{
            console.log(res.data);
            if (res.data.code == 200){
                console.log("删除成功");
                document.getElementById('msg').innerHTML = "删除成功";
                location.reload();
                setTimeout(()=>{
                    document.getElementById('msg').innerHTML = "";
                }, 2000);
            }else {
                console.log("删除失败");
                document.getElementById('msg').innerHTML = res.data.desc;
                setTimeout(()=>{
                    document.getElementById('msg').innerHTML = "";
                }, 2000);
            }
        }).catch(e=>{
            console.log(e);
            console.log("删除出现异常");
            document.getElementById('msg').innerHTML = "删除出现异常";
            setTimeout(()=>{
                document.getElementById('msg').innerHTML = "";
            }, 2000);
        })
    }
</script>
<div class="main">
    <h2 style="text-align: center">订单评价数据列表</h2>
    <div id="msg"></div>
    <div style="margin-top: 20px">
        <table class="table">
            <thead>
            <tr>
                <th style="text-align: center">用户</th>
                <th style="text-align: center">订单</th>
                <th style="text-align: center">商品</th>
                <th style="text-align: center">评分</th>
                <th style="text-align: center">内容</th>
                <th style="text-align: center">发布日期</th>
                <th style="text-align: center" width="150">操作</th>
            </tr>
            </thead>
            <tbody>
            <c:forEach items="${topicList}" var="topic">
                <tr align="center">
                    <td>${topic.username}</td>
                    <td>${topic.orderNum}</td>
                    <td>${topic.goodName}</td>
                    <td>${topic.num}</td>
                    <td>${topic.contents}</td>
                    <td>${topic.createTime}</td>
                    <td>
                        <a onclick="{if(confirm('确定要删除吗?')){
                            deleteTopic('/topic/deleteTopicById/${topic.topicId}');
                        }return false;}">删除</a>
                    </td>
                </tr>
            </c:forEach>
            </tbody>
        </table>
    </div>
</div>
</body>
</html>
